package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.OrderDetailGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/11/30.
 */
public class OrderDetailAddAdapter extends ArrayAdapter<OrderDetailGet.Addeds> {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<OrderDetailGet.Addeds> addLists;

    public OrderDetailAddAdapter(Context context, List<OrderDetailGet.Addeds> addLists) {
        super(context, 0, addLists);

        this.context = context;

        layoutInflater = LayoutInflater.from(context);

        this.addLists = addLists;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        OrderDetailGet.Addeds addeds = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_order_detail_list, null)));

            convertView.setTag(viewHolder);
        } else {

            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (position == addLists.size()-1) {

            viewHolder.item_order_detail_list_line_tv.setVisibility(View.GONE);

        } else {

            viewHolder.item_order_detail_list_line_tv.setVisibility(View.VISIBLE);

        }

        viewHolder.item_order_list_goods_count_tv.setText(addeds.num);
        viewHolder.item_order_list_goods_name_tv.setText(addeds.title);
        viewHolder.item_order_list_money_tv.setText(addeds.deprice);

        GlideLoader.getInstance().get(context, addeds.picurl, viewHolder.item_order_list_goods_img_iv, R.mipmap.img_holder, GlideLoader.TYPE_IMAGE_FILLET);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_order_list_goods_img_iv) private ImageView item_order_list_goods_img_iv;
        @BoundView(R.id.item_order_list_goods_name_tv) private TextView item_order_list_goods_name_tv;
        @BoundView(R.id.item_order_list_goods_count_tv) private TextView item_order_list_goods_count_tv;
        @BoundView(R.id.item_order_list_money_tv) private TextView item_order_list_money_tv;

        @BoundView(R.id.item_order_detail_list_line_tv) private TextView item_order_detail_list_line_tv;

    }

}
